{__NOLAYOUT__}
<layout name="no_nav" />
<style type="text/css">
	.my-list {
		margin: 1em auto;
		width: 96%;
		overflow: hidden;
		border: #ddd solid 1px;
		border-radius: 5px;
	}
	.menu-list-inner{
		margin-right: .9em;
	}
	.my-head-content{
	    position: relative;
	    padding-top: .2em;
	}
	.my-head-name{
	    margin-top: .8em;
	}
	.my-head-type{
	    position: absolute;
        left: 0;
        right: 0;
        top: 4.5em;
	}
	.my-head-type span{
	    font-size: 80%;
	    display: inline-block;
	    background: #7b72e9;
	    color: #fff;
	    padding: 2px 10px;
        border-radius: 5px;	    
	}
</style>
<!-- TOPBAR -->
<header class="top-bar flex-row">
	<a class="row-item row-item-auto top-bar-back" href="javascript:window.history.back()">返回</a>
	<h3 class="row-item top-bar-name">个人中心</h3>
	<a class="row-item row-item-auto top-bar-menu" href="{$config.url}">主页</a>
</header>

<!-- 头像 -->
<section class="my-head">
	<figure class="my-head-content">
		<p class="my-head-img">
			<img id="head" src="{$user.face}" alt="" style="border-radius: 50%;">
			<input id="upload-head" class="my-header-file-input" type="file" accept="image/*">
		</p>
		<p class="my-head-type"><span>{$user.typeName|default='会员'}</span></p>
		<p class="my-head-name">{$user.nickname}</p>
	</figure>
</section>

<section class="my-list menu-list">
    <a class="menu-list-item menu-list-link" href="{:U('DisShop/dealerIndex','sid='.$sid)}">
        <div class="menu-list-media"></div>
        <div class="menu-list-inner">
            <p class="menu-list-title">金牌会员特享商品</p>
        </div>
    </a>
    <eq name="config.openInBrowser" value="1">
    <if condition="$user['type'] egt 4">
    <a class="menu-list-item menu-list-link" href="{:U('DisShopSpace/index','sid='.$sid)}">
        <div class="menu-list-media"></div>
        <div class="menu-list-inner">
            <p class="menu-list-title">金牌会员个人中心</p>
        </div>
    </a>
    </if>
    </eq>
	<if condition="$config['agent_shop_config'] && $config['agent_shop_config']['enabled'] && ($isAgent || $isBought) || ($user['id'] eq 29)">
	<a class="menu-list-item menu-list-link" href="{:U('DisShopAgent/my','sid='.$sid)}">
		<div class="menu-list-media"></div>
		<div class="menu-list-inner">
			<p class="menu-list-title">代理商专区</p>
		</div>
	</a>
	</if>
</section>

<section class="my-list menu-list">
	<foreach name="types" item="vo" key="k">
		<a class="menu-list-item menu-list-link" href="{:U('DisShopOrder/list','type='.$k.'&sid='.$sid)}">
			<div class="menu-list-media"></div>
			<div class="menu-list-inner">
				<p class="menu-list-title">{$vo}</p>
			</div>
		</a>
	</foreach>
</section>

<notEmpty name="giftsTypes">
<section class="my-list menu-list">
	<foreach name="giftsTypes" item="vo" key="k">
	<a class="menu-list-item menu-list-link" href="{:U('DisShopGiftsOrder/list','type='.$k.'&sid='.$sid)}">
		<div class="menu-list-media"></div>
		<div class="menu-list-inner">
			<p class="menu-list-title">{$vo}</p>
		</div>
	</a>
	</foreach>
</section>
</notEmpty>

<section class="my-list menu-list">
	<foreach name="redPacketTypes" item="vo" key="k">
		<a class="menu-list-item menu-list-link" href="{:U('DisShopRedPakcet/list','type='.$k.'&sid='.$sid)}">
			<div class="menu-list-media"></div>
			<div class="menu-list-inner">
				<p class="menu-list-title">{$vo}</p>
			</div>
		</a>
	</foreach>
</section>

<section class="my-list menu-list">
	<a class="menu-list-item" href="{:U('DisShop/myCust', 'sid='.$sid)}">
		<div class="menu-list-inner">
			<p class="menu-list-title">我的客户({$user.subCount})</p>
		</div>
	</a>
	<a class="menu-list-item" href="{:U('DisShop/disOrder', 'sid='.$sid)}">
		<div class="menu-list-inner">
			<p class="menu-list-title">我的订单({$user.orderCount})</p>
		</div>
	</a>
	<a class="menu-list-item" href="{:U('DisShop/myBonus', 'sid='.$sid)}">
		<div class="menu-list-inner">
			<p class="menu-list-title">我的积分({$user.bonus})</p>
		</div>
	</a>
</section>

<section class="my-list menu-list" id="dealer_count">
</section>
<script type="text/javascript">
$(function(){
	$.post("{:U('DisShop/getRecommendedDealerCount', 'sid='.$sid, false, true)}", {}, function(res) {
		var group = ['直属金牌会员', '二级金牌会员', '三级金牌会员'];
		for( var i=0; i<group.length; i++) {
			var groupName = group[i];
			var html = "<a class=\"menu-list-item\" href=\"__CONTROLLER__/downDealer/sid/{$sid}/level/"+i+"\">" + 
								"<div class=\"menu-list-inner\">" +
								"<p class=\"menu-list-title\">"+groupName+"("+res.extra[i]+"人)</p>" +
								"</div>" +
						"</a>";
			$("#dealer_count").append(html);
		}
	});
});
</script>

<section class="my-list menu-list" id="distribution_count">
</section>
<script type="text/javascript">
$(function(){
	$.post("{:U('DisShop/getDistributionCount', 'sid='.$sid, false, true)}", {}, function(res) {
		var group = ['今日收入', '一周收入', '一个月收入'];
		for( var i=0; i<group.length; i++) {
			var groupName = group[i];
			var html = "<a class=\"menu-list-item\">" + 
								"<div class=\"menu-list-inner\">" +
								"<p class=\"menu-list-title\">"+groupName+"("+res.extra[i]+" 元)</p>" +
								"</div>" +
						"</a>";
			$("#distribution_count").append(html);
		}
	});
});
</script>

<section class="my-list menu-list">
	<a class="menu-list-item" href="{:U('disShopDeliverAddress/deliverAddressList', 'sid='.$sid)}">
		<div class="menu-list-inner">
			<p class="menu-list-title">地址管理</p>
		</div>
	</a>
	<a class="menu-list-item" href="{:U('DisShop/myBankList', 'sid='.$sid.'&mode=edt')}?back={$backUrl}">
		<div class="menu-list-inner">
			<p class="menu-list-title">已绑定银行卡</p>
		</div>
	</a>
</section>

<include file="navBar" />

<script type="text/javascript">
	$(function() {

		$("#upload-head").on("change", function(e) {

			var f = e.target.files[0];
			if (f.type.match(/image/)) {
				if (f.size > 204800) {
					APP.alert("上传的头像不能大于200KB");
					return false;
				};
			} else {
				APP.alert("请选择图片上传");
				return false;
			};

			var xhr = new XMLHttpRequest(),
				fm = new FormData();
			fm.append("sid", 1);
			fm.append("Filedata", f);
			xhr.onreadystatechange = function(e) {
				if (xhr.readyState === 4 && xhr.status === 200) {
					var response = JSON.parse(xhr.responseText);
					$("#head").attr("src", response.extra.url)
				};
			};
			xhr.open("post", "{:U('User/face')}", true);
			xhr.send(fm);

		});
		
	});
</script>
